package com.atguigu.study.base.callable;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

//class MyThread  implements Runnable{
//
//    @Override
//    public void run() {
//
//    }
//}
class MyThread2 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("我爱学习");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return 1229;
    }
}

/**
 * @Author 快点干早点散
 * @Create 2025/4/25 15:37
 * Description:
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        FutureTask futureTask = new FutureTask(() -> {System.out.println("lambda");return 222;});
        FutureTask futureTask = new FutureTask(new MyThread2());
        Thread thread1 = new Thread(futureTask, "T1");
        thread1.start();
//        System.out.println(futureTask.get());
        FutureTask futureTask1=new FutureTask(new MyThread2());
        Thread thread2=new Thread(futureTask1,"T2");
        thread2.start();
        System.out.println(Thread.currentThread().getName());
        System.out.println(futureTask.get());

    }
}
